package com.aiguigu.gulimall.product.controller;

import com.aiguigu.gulimall.product.entity.AdmissionCard;
import com.aiguigu.gulimall.product.service.ProblemService;
import com.itextpdf.text.DocumentException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * 官网地址：https://www.yuque.com/easyexcel/doc/read
 */
@RestController
@RequestMapping("/easy")
public class EasyController {

    @Resource
    private ProblemService problemService;

    @GetMapping("/test")
    public void exportQuExcel(HttpServletResponse response) {
        problemService.exportQuExcel(response);
    }

    @GetMapping("/download")
    public void download(HttpServletResponse response) {
        problemService.generateWordXWPFDocument(response);
    }

    @PostMapping("/admissioncard")
    public void generatorAdmissionCard(HttpServletResponse response) throws IOException {
        try {
            problemService.generatorAdmissionCard(response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }



    @PostMapping("/pdf")
    public void exportPdf(HttpServletResponse response){
        try {
            problemService.exportPdf(response);
        } catch (DocumentException | FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
